<template>
  <div class="main">
    <div class="left">
      <div id="bottom" :style="{ width: '100%', height: '300px' }"></div>
      <div id="top" :style="{ width: '100%', height: '250px' }"></div>
    </div>
    <div class="right">
      <div id="main" :style="{ width: '100%', height: '400px' }"></div>
    </div>
  </div>
</template>

<script>
import webservice from "../../utils/webservice";
export default {
  data() {
    return {
      tableData: [],
      Title: "欢迎使用后台管理系统(V1.0)",
    };
  },
  created() {
    this.getData();
  },
  mounted() {
    this.echartsUserData();
    this.echartsPersonData();
    this.echartsWorkData();
  },
  methods: {
    echartsUserData() {
      var chartDom = document.getElementById("top");
      var myChart = this.$echarts.init(chartDom);
      var option;

      option = {
        title: {
          text: "男女比例",
          left: "center",
          textStyle: {
            color: "#ccc",
          },
        },
        tooltip: {
          trigger: "item",
        },
        legend: {
          orient: "vertical",
          left: "left",
          textStyle: {
            color: "#ccc",
          },
        },
        series: [
          {
            name: "男女比例",
            type: "pie",
            radius: "50%",
            data: [
              { value: this.tableData.sex0, name: "男" },
              { value: this.tableData.sex1, name: "女" },
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      };

      option && myChart.setOption(option);
    },
    echartsPersonData() {
      var chartDom = document.getElementById("bottom");
      var myChart = this.$echarts.init(chartDom);
      var option;
      option = {
        title: {
          text: "人员类别统计",
          left: "center",
          textStyle: {
            color: "#ccc",
          },
        },
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)",
        },
        legend: {
          left: "center",
          top: "30",
          data: ["会员", "教练", "管理员"],
          textStyle: {
            color: "#ccc",
          },
        },
        series: [
          {
            name: "人员统计",
            type: "pie",
            radius: [20, 100],
            center: ["50%", "50%"],
            roseType: "radius",
            itemStyle: {
              borderRadius: 5,
            },
            top: "10%",
            label: {
              show: false,
            },
            emphasis: {
              label: {
                show: true,
              },
            },
            data: [
              { value: this.tableData.uType0, name: "会员" },
              { value: this.tableData.uType1, name: "教练" },
              { value: this.tableData.uType2, name: "管理员" },
            ],
            width: 1,
            hieght: 1,
            left: "center",
          },
        ],
      };

      option && myChart.setOption(option);
    },
    echartsWorkData() {
      var chartDom = document.getElementById("main");
      var myChart = this.$echarts.init(chartDom);
      var option;
      option = {
        legend: {
          data: ["排班数量", "请假数量"],
          textStyle: {
            color: "#ccc",
          },
        },
        xAxis: [
          {
            type: "category",
            data: [
              this.tableData.list[0].date,
              this.tableData.list[1].date,
              this.tableData.list[2].date,
              this.tableData.list[3].date,
              this.tableData.list[4].date,
              this.tableData.list[5].date,
              this.tableData.list[6].date,
            ],
          },
        ],
        yAxis: [
          {
            type: "value",
          },
        ],
        series: [
          {
            name: "排班数量",
            type: "bar",
            emphasis: {
              focus: "series",
            },
            data: [
              this.tableData.list[0].type0Num,
              this.tableData.list[1].type0Num,
              this.tableData.list[2].type0Num,
              this.tableData.list[3].type0Num,
              this.tableData.list[4].type0Num,
              this.tableData.list[5].type0Num,
              this.tableData.list[6].type0Num,
            ],
          },
          {
            name: "请假数量",
            type: "bar",
            stack: "广告",
            emphasis: {
              focus: "series",
            },
            data: [
              this.tableData.list[0].type1Num,
              this.tableData.list[1].type1Num,
              this.tableData.list[2].type1Num,
              this.tableData.list[3].type1Num,
              this.tableData.list[4].type1Num,
              this.tableData.list[5].type1Num,
              this.tableData.list[6].type1Num,
            ],
          },
        ],
      };

      option && myChart.setOption(option);
    },
    getData() {
      webservice.HttpPost("/api/user/indexStatistics", "", (data) => {
        if (data.code === 200) {
          this.tableData = data.data;
          this.echartsPersonData();
          this.echartsUserData();
          this.echartsWorkData();
        }
      });
    },
  },
};
</script>

<style>
.main {
  display: flex;
  width: 100%;
}
.left {
  margin-left: 30px;
  margin-top: 10px;
  width: 40%;
}
.right {
  width: 60%;
  margin-top: 100px;
}
</style>
